const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin'); //清除之前打包的文件

module.exports = {
    mode: 'development',
    entry: './src/js/entry.js',   // 入口文件
    output: {                     // 输出配置
        filename: 'bundle.js',      // 输出文件名
        path: path.resolve(__dirname, 'dist')   //输出文件路径配置
    },
    devServer: {
        static: './dist', //web-pack-server寻找static参数目录下的index.html
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader', //处理css样式添加到dom中
                    'css-loader' // 加载css的loader
                ]
            },
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: 'asset/resource',
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({template:'./index.html'}),
        new CleanWebpackPlugin(),
    ]
};